<template>
	<view class="page">
		<uni-forms ref="baseForm" :modelValue="baseFormData">
			<uni-forms-item label="收货人" required><uni-easyinput v-model="baseFormData.name" placeholder="请输入收货人姓名" /></uni-forms-item>
			<uni-forms-item label="手机号码" required><uni-easyinput v-model="baseFormData.phone" placeholder="请输入收货人手机号码" /></uni-forms-item>
			<picker class="address" mode="region" @change="bindAddressChange">点击选择收货地址</picker>
			<view class="addressText">{{ address }}</view>
			<view class="line4">————————————————————————————————————————————————————</view>
			<uni-forms-item label="详细地址" required><uni-easyinput v-model="baseFormData.place" placeholder="请输入详细地址" /></uni-forms-item>
		</uni-forms>
		<button class="btn" @click="update">确认修改</button>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				baseFormData: {
					name: '',
					phone: '',
					place:'',
					id:''
				},
				address:'',
			}
		},
		onLoad: function(options) {
			let that = this;
			that.baseFormData.name = options.name;
			that.baseFormData.phone = options.phone;
			that.baseFormData.address = options.address;
			that.baseFormData.place = options.address;
			that.address = options.address;
			that.baseFormData.id = options.id;
		},
		methods: {
			bindAddressChange: function(e) {
				this.region = e.target.value;
				this.address = this.region;
			},
			update() {
				let that = this;
				let data = {
					address: that.address,
					name: that.baseFormData.name,
					phone: that.baseFormData.phone,
					id: that.baseFormData.id
				};
				that.ajax(that.url.updateAddressInfo, 'POST', data, function(resp) {
					uni.showToast({
						icon: 'none',
						title: '修改成功'
					});
					setTimeout(function() {
						uni.navigateBack(1);
					}, 1000);
				});
			}
		}
	}
</script>

<style lang="less">
@import url("edit_addressInfo.less");
</style>
